package com.hundsun.yr.universal.p2p.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hundsun.mobile.zwgt.R;
/**
 * 可编辑的itemview
 * @author tonglj
 */
public class ItemEditView extends LinearLayout implements OnClickListener{
	private TextView valueText,titleText;
	private EditText valueEdit;
	private boolean editable;
	

	public ItemEditView(Context context) {
		this(context,null);
	}

	public ItemEditView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context,attrs);
	}
	

	private void init(Context context, AttributeSet attrs){
		setOrientation(LinearLayout.HORIZONTAL);
		View.inflate(context, R.layout.item_editview, this);
		valueText = (TextView)findViewById(R.id.item_editview_value);
		titleText = (TextView)findViewById(R.id.item_editview_name);
		valueEdit = (EditText)findViewById(R.id.et_item_editview_value);
		TypedArray  typearr = context.obtainStyledAttributes(attrs, R.styleable.ItemEditView);
		int hintId = typearr.getResourceId(R.styleable.ItemEditView_hint, R.string.empty);
		setHint(hintId);
		int nameId = typearr.getResourceId(R.styleable.ItemEditView_name, R.string.empty);
		setName(nameId);
		int valId = typearr.getResourceId(R.styleable.ItemEditView_value, R.string.empty);
		setValue(valId);
		editable = typearr.getBoolean(R.styleable.ItemEditView_editable, false);
		setEditAble(editable);
	}
	
	public void setHint(int resid){
		valueText.setHint(resid);
		valueEdit.setHint(resid);
	}
	
	public void setHint(String resid){
		valueText.setHint(resid);
		valueEdit.setHint(resid);
	}
	
	public void setValue(int resid){
		valueText.setText(resid);
		valueEdit.setText(resid);
	}
	
	public void setValue(String resid){
		valueText.setText(resid);
		valueEdit.setText(resid);
	}
	
	/**
	 * 设置网络异常
	 * @param color
	 */
	public void  setTextColor(int color){
		valueText.setTextColor(color);
	}
	
	public void setName(int resid){
		titleText.setText(resid);
	}
	
	public void setEditAble(boolean flag){
		if(flag){
			valueEdit.setVisibility(View.VISIBLE);
			valueText.setVisibility(View.GONE);
		}else{
			valueText.setVisibility(View.VISIBLE);
			valueEdit.setVisibility(View.GONE);
		}
	}
	
	public EditText getEditText(){
		return valueEdit;
	}
	
	public String getValue(){
		return 	valueEdit.getText().toString();
	}

	@Override
	public void onClick(View v) {
		if(v==this){
			
		}
		
	}
	
}
